<?php
// +----------------------------------------------------------------------
// | YBlog
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.yhustc.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yhustc <yhustc@gmail.com>
// +----------------------------------------------------------------------
// $Id$

/**
 +------------------------------------------------------------------------------
 * YBlog友情链接管理模块
 +------------------------------------------------------------------------------
 * @author    yhustc <yhustc@gmail.com>
 * @version   $Id$
 +------------------------------------------------------------------------------
 */


class LinksAction extends BaseAction
{
	/**
     +----------------------------------------------------------
     * 友情链接列表
     +----------------------------------------------------------
     * @access public 
     +----------------------------------------------------------
     */
	function index()
	{
		$linkDao = D("Links");
		$linkList = $linkDao->findAll();
		
		$this->assign("pageFile","Links:index");
		$this->assign("linkList",$linkList);
		$this->layout();
	}
	
	/**
     +----------------------------------------------------------
     * 保存友情链接添加/编辑
     +----------------------------------------------------------
     * @access public 
     +----------------------------------------------------------
     */
	function edit()
	{
		$linkDao = D("Links");
		$rs = $linkDao->create();
		if(!$rs)
			$this->error($linkDao->getError());
		
		$rs = false;
		if(empty($_POST["link_id"]))
		{
			$rs = $linkDao->add();
			$success = "添加友情链接成功!";
			$error = "添加友情链接失败!";
		}
		else
		{
			$rs = $linkDao->save();
			$success = "修改友情链接成功!";
			$error = "修改友情链接失败!";
		}
		
		if($rs)
			$this->success($success);
		else
			$this->error($error);
	}
	
	/**
     +----------------------------------------------------------
     * 删除指定的友情链接
     +----------------------------------------------------------
     * @access public 
     +----------------------------------------------------------
     */
	function del()
	{
		$rs = 0;
		$linkDao = D("Links");
		if(!empty($_GET["link_id"]))
			$rs = $linkDao->delete("link_id='".$_GET["link_id"]."'");
		else
			$rs = $linkDao->delete("link_id IN (".implode(",",$_POST["link_id"]).")");
			
		if($rs)
			$this->success("删除友情链接成功!");
		else
			$this->error("删除友情链接失败!");
	}
}
?>